<template>
    <div>
        <!-- Header组件 -->
        <Header title="详情页"> 
             <template v-slot:left>
                 <span @click="$router.go(-1)">&lt;</span>  
             </template>
             <template v-slot:right>
                 <span >...</span>  
             </template>
        </Header>
        <div class="list">
            <div class="item" >
                <div class="pic">
                    <img :src="$route.params.pic" alt="">
                </div>
                <div class="text">
                    <div class="name">{{$route.params.name}}</div>
                    <div class="buycount">已售: {{$route.params.buyCount}}件</div>
                    <div class="price">单价: ¥{{$route.params.price}}</div>
                </div>
                <div class="btn" @click="addToCart($route.params)">加入购物车</div>
            </div>
        </div>
    </div>
</template>

<script>

import {mapMutations} from 'vuex'
export default {
    data(){
        return {

        }
    },
    methods:{
        ...mapMutations(['addToCart'])
    }
}
</script>
<style scoped>
.list .item{
    position: relative;
    display: flex;
    margin: 20px;
}
.list .item .pic{
    width: 25%;
    margin-right: 20px;
}
.list .item .pic img{
    width: 100%;
}
.list .item .text{
    width: 75%;
}
.list .item .text .name{
    color: #333;
    white-space: nowrap;/* 文本不换行 */
    text-overflow: ellipsis;/* 文本溢出 显示省略号 */
    overflow: hidden;/* 溢出盒子,隐藏 */
}
.list .item .btn{
    position: absolute;
    right: 0;
    bottom: 0;
    background-color: red;
    color: white;
    padding: 5px 20px;
}
</style>